cmake_minimum_required(VERSION 3.5)
project(network-check LANGUAGES CXX)

set(TOP_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../)
set(NETWORK_CHECK_DIR ${CMAKE_CURRENT_LIST_DIR})

set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall")
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")



find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets LinguistTools X11Extras Network DBus Concurrent REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools X11Extras Network DBus Concurrent REQUIRED)
find_package(KF5WindowSystem REQUIRED)
execute_process(COMMAND bash ${NETWORK_CHECK_DIR}/translations/generate_translations_ts.sh
                WORKING_DIRECTORY ${NETWORK_CHECK_DIR})
execute_process(COMMAND bash ${NETWORK_CHECK_DIR}/translations/generate_translations_qm.sh
                WORKING_DIRECTORY ${NETWORK_CHECK_DIR})
#Gsetting
find_package(PkgConfig REQUIRED)
pkg_check_modules(QGSETTINGS REQUIRED IMPORTED_TARGET gsettings-qt)
pkg_check_modules(KYSDKKABASE_PKG kysdk-kabase)
pkg_check_modules(KYSDKQTWIDGETS_PKG kysdk-qtwidgets)
pkg_check_modules(KYSDK_WAYLANDHELPER kysdk-waylandhelper)

# add ukui log
#file(GLOB_RECURSE UKUI_LOG4QT "/usr/lib/libukui-log4qt.so")

link_directories(${PROJECT_SOURCE_DIR}/../lib)

include_directories(
${PROJECT_SOURCE_DIR}/include/
${PROJECT_SOURCE_DIR}/../libBase/include/
${PROJECT_SOURCE_DIR}/../customWidget/
${PROJECT_SOURCE_DIR}/../Observer_Notifier/
${PROJECT_SOURCE_DIR}/../libNWDBus/include
${PROJECT_SOURCE_DIR}/../HWCheck/
${PROJECT_SOURCE_DIR}/../IPCheck/
${PROJECT_SOURCE_DIR}/../DHCPCheck/
${PROJECT_SOURCE_DIR}/../DNSCheck/
${PROJECT_SOURCE_DIR}/../HostCheck/
#${PROJECT_SOURCE_DIR}/../ProxyCheck/
${PROJECT_SOURCE_DIR}/../NetCheck/
)
file(GLOB source_SRC
    "src/*.cpp"
    "include/*.h"
    "src/*.ui"
    "../customWidget/*.cpp"
    "../customWidget/*.h"
    "../customWidget/*.ui"
    "../Observer_Notifier/*.cpp"
    "../Observer_Notifier/*.h"
    "${TOP_DIR}/interface/kymanager_plugin.cpp")

SET(ui_RESOURCE ${PROJECT_SOURCE_DIR}/pictures.qrc)
#set(TS_FILES ${PROJECT_SOURCE_DIR}/translations/kylin-netcheck-tools_zh_CN.ts)

#QT5_CREATE_TRANSLATION(QM_FILES
#             ${source_SRC}
#             ${TS_FILES})

add_library(${PROJECT_NAME} SHARED
  ${source_SRC}
  ${ui_RESOURCE}
  ${QM_FILES}
)

#SDKt添加
target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDKQTWIDGETS_PKG_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDKQTWIDGETS_PKG_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${KYSDKQTWIDGETS_PKG_LIBRARIES})

target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDKKABASE_PKG_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${KYSDKKABASE_PKG_LIBRARIES})
#SDKt添加

target_include_directories(${PROJECT_NAME} PRIVATE ${KYSDK_WAYLANDHELPER_INCLUDE_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${KYSDK_WAYLANDHELPER_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${KYSDK_WAYLANDHELPER_LIBRARIES})

target_include_directories(${PROJECT_NAME} PRIVATE ${TOP_DIR}/interface)
target_include_directories(${PROJECT_NAME} PRIVATE ${TOP_DIR}/3rdparty/kyplugin)

link_directories(${PROJECT_SOURCE_DIR}/../plugins)
link_directories(${PROJECT_SOURCE_DIR}/../lib)
target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::X11Extras Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::DBus Qt${QT_VERSION_MAJOR}::Concurrent)
target_link_libraries(${PROJECT_NAME} KF5::WindowSystem)

target_link_libraries(${PROJECT_NAME} PkgConfig::QGSETTINGS)
target_link_libraries(${PROJECT_NAME}  -lX11)
target_link_libraries(${PROJECT_NAME}  ${UKUI_LOG4QT})

target_link_libraries(${PROJECT_NAME} libBase)
target_link_libraries(${PROJECT_NAME} HWCheck)
target_link_libraries(${PROJECT_NAME} IPCheck)
target_link_libraries(${PROJECT_NAME} DHCPCheck)
target_link_libraries(${PROJECT_NAME} DNSCheck)
target_link_libraries(${PROJECT_NAME} HostCheck)
#target_link_libraries(${PROJECT_NAME} ProxyCheck)
target_link_libraries(${PROJECT_NAME} NetCheck)

file(GLOB TRANS
    "${NETWORK_CHECK_DIR}/translations/kylin-netcheck-tools_zh_CN.qm"
    "${NETWORK_CHECK_DIR}/translations/kylin-netcheck-tools_bo_CN.qm"
    "${NETWORK_CHECK_DIR}/translations/kylin-netcheck-tools_ug.qm"
    "${NETWORK_CHECK_DIR}/translations/kylin-netcheck-tools_kk.qm"
    "${NETWORK_CHECK_DIR}/translations/kylin-netcheck-tools_ky.qm")
install(FILES ${TRANS} DESTINATION  /usr/share/kylin-os-manager/translations/)

install(TARGETS ${PROJECT_NAME} DESTINATION /opt/kylin-os-manager/plugins/)
#install(FILES ${PROJECT_SOURCE_DIR}/NWCheckTool.desktop DESTINATION /usr/share/applications/)
install(FILES ${PROJECT_SOURCE_DIR}/data/org.kylin.nw.check.gschema.xml DESTINATION /usr/share/glib-2.0/schemas/)
#install(FILES ${PROJECT_SOURCE_DIR}/data/Applogo.png DESTINATION /usr/share/icons/)
install(FILES ${PROJECT_SOURCE_DIR}/config/kylin-netcheck-tools.conf DESTINATION /etc/kylin-os-manager/net-check/)
